﻿using System;
using System.Collections.Generic;

namespace Flagwind.Data
{
	/// <summary>
	/// 实体字段缓存
	/// </summary>
	public class EntityFieldsCache
	{
		private static Dictionary<string, EntityInfo> dict = new Dictionary<string, EntityInfo>();
		private static object _syncObj = new object();

		/// <summary>
		/// 获取缓存项，如果没有，将自动创建一个
		/// </summary>
		/// <param name="entityType">实体类类型</param>
		/// <returns></returns>
		public static EntityInfo Item(Type entityType)
		{
			if(dict.ContainsKey(entityType.FullName))
			{
				return dict[entityType.FullName];
			}
			lock(_syncObj)
			{
				if(dict.ContainsKey(entityType.FullName))
				{
					return dict[entityType.FullName];
				}
				else
				{
					EntityInfo ef = new EntityInfo(entityType);
					dict.Add(entityType.FullName, ef);

					return ef;
				}
			}
		}
	}
}